package chapter06;

import java.util.ArrayList;
import java.util.Iterator;

public class Test04_iterator {
    public static void main(String[] args) {
        ArrayList list = new ArrayList();
        list.add("张三");
        list.add(25);
        list.add(3.14);
        //获得迭代器
        Iterator iterator = list.iterator();
        while (iterator.hasNext()){
//            System.out.println(iterator.next());
            Object next = iterator.next();
//            if("张三".equals(next)){
//                list.remove(next);
//            }
//            if("张三".equals(next)){
//                iterator.remove();
//            }
        }
        for(int i=0;i<list.size();i++){
            System.out.println(list.get(i));
            if(list.get(i).equals("张三")){
                list.set(i,"李四");
            }
        }
        for (Object e: list) {
            System.out.println(e);
            //更改e的值
            if(e.equals("张三")){
                e = "田七";
            }
        }
        System.out.println();
    }
}
